package vn.edu.uit.game_show;

import vn.edu.uit.game_show.DragDrop.DeleteZone;
import vn.edu.uit.game_show.DragDrop.DragController;
import vn.edu.uit.game_show.DragDrop.DragLayer;
import vn.edu.uit.game_show.DragDrop.DragSource;
import vn.edu.uit.game_show.DragDrop.ImageCell;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SendResult extends Activity implements OnTouchListener,
		OnClickListener, OnLongClickListener {

	private DragController mDragController;
	private DragLayer mDragLayer;
	private DeleteZone mMailBoxZone;
	ImageCell imgResult;

	RelativeLayout rlResult;
	TextView tvResult;
	String time = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.result_screen);

		mDragController = new DragController(this);
		mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
		mDragLayer.setDragController(mDragController);
		mDragController.setDragListener(mDragLayer);
		
		Intent startIntent = getIntent();
		if (startIntent != null) {
			Bundle b = startIntent.getExtras();
			time = b.getString("Time");
		}
		
		tvResult = (TextView) findViewById(R.id.tvResultTime);
		tvResult.setText("Thời gian hoàn thành: "+time);

		rlResult = (RelativeLayout) findViewById(R.id.rlMail);

		imgResult = new ImageCell(this);
		imgResult.setImageResource(R.drawable.result);
		imgResult.setContentDescription("result");

		imgResult.mEmpty = false;
		imgResult.mCellNumber = -1;
		imgResult.setOnTouchListener(this);
		imgResult.setOnClickListener(this);
		imgResult.setOnLongClickListener(this);
		rlResult.addView(imgResult);

		mMailBoxZone = (DeleteZone) findViewById(R.id.mailboxZone);
		mMailBoxZone.delActivity(this, this, true);
	}

	public boolean startDrag(View v) {
		DragSource dragSource = (DragSource) v;
		mDragController.startDrag(v, dragSource, dragSource,
				DragController.DRAG_ACTION_MOVE);

		return true;
	}

	public boolean onLongClick(View v) {
		// TODO Auto-generated method stub
		return false;
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

	public boolean onTouch(View v, MotionEvent event) {
		boolean handleHere = false;
		int action = event.getAction();

		switch (action) {
		case MotionEvent.ACTION_DOWN:
			handleHere = startDrag(v);
			break;
		}
		return handleHere;
	}
}
